/***************************************
 * Author: Nikhil Kishore
 * Date: July 19, 2014
 * Description: Random test generator
 * for the sea_hag card
***************************************/



#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"


int seaHagRandomTest(struct gameState *post){

	struct gameState pre;
	memcpy (&pre, post, sizeof(struct gameState));
    	int currentPlayer = pre.whoseTurn;

	int i;

    	for (i = 0; i < pre.numPlayers; i++){
   	   if (i != currentPlayer){
  	      pre.discard[i][pre.discardCount[i]] = pre.deck[i][pre.deckCount[i]--];	
	      pre.deckCount[i]--;
  	      pre.discardCount[i]++;
  	      pre.deck[i][pre.deckCount[i]--] = curse;
   	   }
    	}

    	int result = cardEffect(sea_hag, -1, -1, -1, post,-1,0);  
    	assert( result ==0);
    
    	int deckCount = pre.deckCount[currentPlayer];
    	assert(memcmp(&pre.deck[currentPlayer], post->deck[currentPlayer], sizeof(int[deckCount])) == 0);
    
    	int handCount = pre.handCount[currentPlayer];
    	assert(memcmp(&pre.hand[currentPlayer], post->hand[currentPlayer], sizeof(int[handCount])) == 0);

	int discardCount = pre.discardCount[currentPlayer];
    	assert(memcmp(&pre.discard[currentPlayer], post->discard[currentPlayer], sizeof(int[handCount])) == 0);
    	assert(memcmp(&pre, post, sizeof(struct gameState)) == 0);

    	if(memcmp(&pre, post, sizeof(struct gameState)) != 0){
           	   printf("\n--Test failed\n");
    	}
    
	return 0;
}


int main () {
    
	int i, n, p;
	struct gameState G;
    
    	printf ("\n\n\nRandom Testing Sea Hag Card.\n");
    
    	SelectStream(2);
    	PutSeed(3);
    
    	for (n = 0; n < 2000; n++) {
   	   for (i = 0; i < sizeof(struct gameState); i++) {
  	      ((char*)&G)[i] = floor(Random() * 256);
   	   }
        
   	   G.numPlayers = floor(Random() * 3) + 2;
   	   p = floor(Random() * G.numPlayers);
  	   G.whoseTurn = p;
        
   	   int j;
        
   	   for( j = 0; j < G.numPlayers; j++){
	      G.discardCount[j] = floor(Random() * MAX_DECK/5);
  	      G.deckCount[j] = floor(Random() * MAX_DECK/5);
  	      G.handCount[j] = floor(Random() * MAX_HAND/5);
            
  	      if(G.discardCount[j] < 10){
  	      }

  	      if(G.deckCount[j] <=10 ){
 	      }

  	      if(G.handCount[j] <=10){
       	      }
            
      	      for (i = 0; i < MAX_DECK; i++) {
     		 G.deck[j][i] = floor(Random() * 25);
     		 G.hand[j][i] = floor(Random() * 25);
     		 G.discard[j][i] = floor(Random() * 25);
       	      }
            
      	      for (i = 0; i < G.discardCount[p]; i++) {
     		 G.discard[j][i] = floor(Random() * 25);
      	      }
        
       	   }
   
  	   seaHagRandomTest(&G);
    	}
    
   	printf ("ALL TESTS OK\n");

  	return 0;
}
